﻿@model IEnumerable<LotteryVoteMVC.Models.LotteryCompany>
@using LotteryVoteMVC.Core
@using LotteryVoteMVC.Models
@using LotteryVoteMVC.Resources
@{
    ViewBag.Title = @Resource.Company;
    Layout = "~/Views/Shared/Main.cshtml";
}
@section Header
{
    <script src="@Url.Content("~/Scripts/jquery-ui-1.8.11.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/Customer/ajaxHelper.js")" type="text/javascript"></script>
    <link href="@Url.Content("~/Content/themes/base/jquery.ui.theme.css")" rel="stylesheet" type="text/css" />
    <link href="@Url.Content("~/Content/TableBase.css")" rel="stylesheet" type="text/css" />
    <script type="text/javascript">
        var addCompany = function () {
            buildFrame("addCompany", 500, 800, "/Company/Add", resource.Add);
        }
        var editCompany = function (company) {
            buildFrame("editCompany", 500, 800, "/Company/Edit/{0}".format(company), resource.Edit);
        }
        var editCycle = function (company) {
            buildFrame("editCycle", 200, 550, "/Company/EditCycle/{0}".format(company), resource.Edit);
        }
    </script>
}
@{int index = 1;}
@if (ViewBag.CurrentUser.Role == Role.Company)
{
    <div id="searchBar">
        @using (Html.BeginForm("UpdateLotteryCompany", "Company"))
        {
            <input type="button" id="create" name="name" value="@Resource.New" onclick="addCompany()" />
            <input type="submit" id="update" name="update" value="@Resource.UpdateLotteryCompany" />
        }
    </div>
}
<table cellpadding="0" cellspacing="0">
    <thead>
        <tr>
            <td>
                @Resource.No
            </td>
            <td>
                @Resource.CompanyName
            </td>
            <td>
                @Resource.Abbreviation
            </td>
            <td>
                @Resource.CompanyType
            </td>
            <td>
                @Resource.Region
            </td>
            <td>
                @Resource.OpenTime
            </td>
            <td>
                @Resource.CloseTime
            </td>
            @if (ViewBag.CurrentUser.Role == Role.Company)
            {
                <td>
                    @Resource.Function
                </td>
            }
        </tr>
    </thead>
    <tbody>
        @foreach (var company in Model)
        { 
            <tr>
                <td>
                    @(index++)
                </td>
                <td>
                    @company.Name
                </td>
                <td>
                    @company.Abbreviation
                </td>
                <td>
                    @company.CompanyType.GetDesc()
                </td>
                <td>
                    @Resource.ResourceManager.GetString(company.Region.ToString())
                </td>
                <td>
                    @company.OpenTime
                </td>
                <td>
                    @company.CloseTime
                </td>
                @if (ViewBag.CurrentUser.Role == Role.Company)
                {
                    <td>
                        <a href="javascript:editCompany(@company.CompanyId)">@Resource.Edit</a> <a href="javascript:editCycle(@company.CompanyId)">@Resource.OpenTime</a>
                        @Html.ActionLink(Resource.Delete, "Delete", new { Id = company.CompanyId }, new { onclick = "return confirm('Are you sure?')" })
                    </td>
                }
            </tr>
        }
    </tbody>
</table>
